rm(list=ls())
library(reshape2)
library(data.table)
library(ggplot2)
## library(polywog)
## library(MASS)
library(Hmisc)
## library(doParallel)
load("ensemble.Rdata")
ensemble$sddistance <- ensemble$sd.distance/.12
ensemble <- ensemble[, sd.distance:=NULL]
ensemble <- ensemble[round==1076]
ensemble <- ensemble[,alpha5:=ifelse(alpha>.5, 1, 0)]

############################
# Box plots of rule shares #
############################
pdata <- ensemble[,list(mean.Ashare, mean.HGshare, mean.Sshare, mean.Hshare, mean.SGshare)]
setnames(pdata, c("mean.Ashare", "mean.HGshare", "mean.Sshare",
                  "mean.Hshare", "mean.SGshare"),
         c("mean1", "mean2", "mean3", "mean4", "mean5"))
pdata <- melt(pdata, measure.vars=patterns("^mean"))[,list(variable, value)]
p <- ggplot(data=pdata, aes(x=variable, y=value))
p <- p + geom_hline(yintercept=.2, colour="grey37")
p <- p + geom_boxplot()
p <- p + theme_bw()
p <- p + theme(panel.grid.major.x = element_blank())
p <- p + theme(panel.grid.major.y = element_blank())
p <- p + theme(panel.grid.minor.x = element_blank())
p <- p + theme(panel.grid.minor.y = element_blank())
p <- p + theme(panel.border = element_blank())
p <- p + theme(axis.line=element_line(colour="black"))
p <- p + scale_x_discrete(labels=c("Aggregator", "Governator", "Sticker",
                              "Hunter", "Satisficing\nGovernator"))
p <- p + xlab("")
p <- p + ylab("Share of Rules in Party-System")
p
ggsave("boxplot.png", dpi=300)


################
# Correlations #
################
rcorr(as.matrix(ensemble[round==1076,list(mean.Ashare, mean.HGshare, mean.Sshare, mean.Hshare, mean.SGshare)]))
